<?php 
set_time_limit(0);

$sleepData=array(20,40,60,80,100,120,140,160,180,200);

$dbhost = 'localhost';
$dbuser = 'root';
$dbpwd  ='sxy7788123456';
$dbName ='si';


    
    $mysqli=$query=NULL;
    $mysqli = new mysqli($dbhost, $dbuser, $dbpwd, $dbName);
    if (!$mysqli->set_charset("utf8")) {printf("Error loading character set utf8: %s\n", $mysqliTwo->error);}
    for ($j=1;$j<=2;$j++){ 
        $num=file_get_contents('./1.txt');
        $dianId=(int)$num;
        $query=$mysqli->query("select id,openid,tb from users where dadui is NULL limit 0, 1");
        if($query->num_rows>0){
        	$userInfo=$query->fetch_array();
        	$tb=$userInfo['tb'];
        	$queryCishu=$mysqli->query("select dadui,fen from ".$tb." where openid='".$userInfo['openid']."' order by fen desc limit 0, 1");
        	if($queryCishu->num_rows>0){
        		$cishuData=$queryCishu->fetch_array();
        		 
        		$mysqli->query("update users set dadui=".$cishuData['dadui'].", fen=".$cishuData['fen']." where id=".$userInfo['id']."  ");
        	}
        }
        if (in_array($j, $sleepData)){
            echo "<br />";
            echo $num;
            echo "<br />";
            sleep(1);
        }
        
        file_put_contents('./1.txt', ($num+1));
    }
    
    echo $num;
    echo "<br />";
    echo 'done';
    
    $mysqli->close();
   // sleep(5);
